package com.fita.scheduler.scheduler;

import com.fita.scheduler.entity.Order;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.fita.scheduler.service.OrderService;

import javax.persistence.EntityManager;
import javax.transaction.TransactionManager;
import java.util.List;


/**
 * @author Guangli Yan
 *
 */
@Component("orderScheduler")
public class OrderScheduler {

    private static final Logger logger = LoggerFactory.getLogger(OrderScheduler.class);
	
    @Autowired
    private OrderService orderService;

	/**
	 * 取消未支付订单
	 */
	public void cancelUnpaidOrder() {
		
		logger.trace("#cancelUnpaidOrder() cancel order start.");

		List<Order> orders = orderService.listNeedCancelUnpaidOrder();

		for (Order order : orders){
			try {
				orderService.cancelUnpaidOrder(order);
			} catch (Exception e) {
				logger.error("cancel unpaid order error, order is [{}], exception is [{}]", order, e);
			}
		}
		logger.trace("#cancelUnpaidOrder() cancel order end.");
	}

	/**
	* @description 自动核销订单
	* @params * @param
	* @return  void
	* @author  LZJ
	* @date  2019/10/17 13:47 *
	*/
//	public void consumeOrder() {
//
//		logger.trace("consume order start. ");
//
//		orderService.consumeOrder();
//
//		logger.trace("consume order end. ");
//
//	}

	public void sendMarkPayEmail(){

		logger.info("start");

		orderService.sendMarkPayEmail();

		logger.info("end");

	}
	
}
